<?php
use yii\helpers\Html;
use common\components\helpers\Fun;
use doumiaoduo\layer\LayerConfirmWidget;
use doumiaoduo\layer\LayerIframeWidget;
use common\components\extenders\MenuManage;
use common\components\widgets\Datetimepicker;
Datetimepicker::widget(['format'=>'Y-m-d',]);
LayerConfirmWidget::widget();
LayerIframeWidget::widget();
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height" id="toolbar">
    <div id="search-area" class="yx-bgf7f7f7 yx-radius5 zx-mg yx-function2 yx-pr0">
        <label>结算机构：</label><?=$data[0]['mechanic_name']?> &nbsp;&nbsp;&nbsp;
        <label>结算课次数：</label><span id="lesson"><?=count($data)?></span> &nbsp;&nbsp;&nbsp;
        <label>结算补贴金额：</label><span id="total"><?=$amount?></span>元 &nbsp;&nbsp;&nbsp;
    </div>
    <div class="docs-main zx-mg">
        <?php $form = \yii\widgets\ActiveForm::begin(['id'=>'myform']); ?>
        <table id="tablesaw" class="tablesaw table yx-table1 yx-table3 table-striped with-check" data-url="<?= \yii\helpers\Url::to() ?>">
            <thead>
            <tr class="yx-bgd2f6ec">
                <th><?=\Yii::t('zhtfrontend','课程');?></th>
                <th><?=\Yii::t('zhtfrontend','补贴金额');?></th>
                <th><?=\Yii::t('zhtfrontend','课次');?></th>
                <th><?=\Yii::t('zhtfrontend','上课日期');?></th>
                <th><?=\Yii::t('zhtfrontend','上课人数');?></th>
                <th><?=\Yii::t('zhtfrontend','结算状态');?></th>
                <th><?=\Yii::t('zhtfrontend','结算类型');?></th>
                <th><?=\Yii::t('zhtfrontend','操作');?></th>
            </tr>
            </thead>
            <?php if($data):?>
                <?php foreach($data as $item):?>
                    <tr data-id="<?=$item['id']?>">
                        <td><?=$item['goods_name']?></td>
                        <td><?=$item['amount']?></td>
                        <td><?=$item['lesson']?></td>
                        <td><?=$item['class_date']?></td>
                        <td><?=$item['people_number']?></td>
                        <td><?=$item['status_name']?></td>
                        <td><?=$item['type']?></td>
                        <td>
                            <?=Html::hiddenInput('ids[]',$item['id'])?>
                            <a class="btn yx-radius2 yx-d-card yx-bgb5b5b5" rel="remove" >移除</a>
                            <?=Html::buttonInput('确认结算',['class'=>"btn yx-radius2 yx-d-card yx-bg65d1d4",'id'=>'settlement_btn'])?>
                            <?=Html::buttonInput('取消结算',['class'=>"btn yx-radius2 yx-d-card yx-bg94d5a2",'onclick'=>'window.history.go(-1);'])?>
                        </td>
                    </tr>
                <?php endforeach?>
            <?php endif?>

        </table>
        <?=Html::hiddenInput('start',$start)?>
        <?=Html::hiddenInput('end',$end)?>
        <?php \yii\widgets\ActiveForm::end(); ?>
    </div>
</div>

<?php
$js = <<<JS
 layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });

  $(document).on('click','#settlement_btn',function(){
        var ids = [];
        $('input[name="ids[]"]').each(function(){
            var id = $(this).val();
            ids.push(id);
        });
        if(ids.length == 0){
              layer.msg('没有要结算的项！',{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
            return false;
        }else{
            $('#myform').submit();
        }
  });
  

  $(document).on('click','a[rel="remove"]',function(){
      var _this = $(this);
      var tr = _this.parents('tr');
      var id = tr.data('id');
      var money = parseFloat(tr.find('td').eq(1).html());
      var total = parseFloat($('#total').html());
      var lesson = parseFloat($('#lesson').html());
      $('#total').html(fomatFloat(total-money,2));
      $('#lesson').html(lesson-1);
      tr.remove();  
  });
  function fomatFloat(src,pos){   
       return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);   
    } 
JS;
$this->registerJS($js);
?>


